from  tkinter import *
import tkinter as tk
from tkinter.filedialog import askdirectory
from PIL import Image, ImageTk
from sympy import im
from main1 import main1
from main2 import main2
from main3copy import main3
from PSO1 import ttd
from PSO2 import ryd
from fx1 import fx1
from fx2 import fx2
root = tk.Tk()
root.title('模糊模型仿真界面')
root.geometry('1000x600') # 这里的乘号不是 * ，而是小写英文字母 x
#数值填写
a="0"
b="0"
c="0"
d="0"
e="0"
f="0"
g="0"
h="0"
i="0"

#实验图像来自examimage文件夹中脚本
#img1 = ImageTk.PhotoImage(Image.open("image\\PSO\TTD\\TTHD.png").resize((200,200)))
img2 = ImageTk.PhotoImage(Image.open("image\\datika\\area_db_2.png").resize((200,200)))
img3 = ImageTk.PhotoImage(Image.open("image\\datika\\area_db_1.png").resize((200,200)))

img4 = ImageTk.PhotoImage(Image.open("image\\hot\\area_db_1.png").resize((200,200)))
img5 = ImageTk.PhotoImage(Image.open("image\\hot\\area_db_2.png").resize((200,200)))
img6 = ImageTk.PhotoImage(Image.open("image\\hot\\area_db_3.png").resize((200,200)))







#样式
# 创建菜单栏
MenuBar = tk.Menu(root)
# 将菜单栏放到主窗口
root.config(menu =MenuBar)
# 创建文件菜单，不显示分窗
fileBar = tk.Menu(MenuBar, tearoff=0)
# 添加文件菜单项
fileBar.add_command(label="打开")
fileBar.add_command(label="保存")
fileBar.add_command(label="另存为")
# 创建分割线
fileBar.add_separator()
fileBar.add_command(label="退出", command=root.destroy)
# 将文件菜单添加到菜单栏
MenuBar.add_cascade(label="文件", menu=fileBar)

#几个按钮
#第0行
'''lb1 = tk.Label(root,bg='white')
lb1.place(x=550, y=20, width=500,height=200)'''


def select1():#在函数体内进行覆盖即可实现刷新
    global img1
    img1 = ImageTk.PhotoImage(Image.open("image\\PSO\TTD\\TTHD.png").resize((200,200)))
    global img2
    global img3
    path = StringVar()
    path_ = askdirectory()
    global path1
    path.set(path_)
    path1=path_
    path1 = path1.replace("/", "\\\\")#\\表示\
    a=ttd(path1)[0]
    b=ttd(path1)[1]
    c=ttd(path1)[2]
    d=ttd(path1)[3]
    g=fx1(path1)[0]
    h=fx1(path1)[1]
    i=fx1(path1)[2]
    #显示路径
    lb = tk.Label(root,text=path1)
    lb.place(x=650, y=0, width=350,height=25)
    
    
    lb3=tk.Label(root,text=a,bg='#ffffff',relief=GROOVE )
    lb3.place(x=800, y=20,width=60,height=25)
    
    lb5=tk.Label(root,text=b,bg='#ffffff',relief=GROOVE)
    lb5.place(x=930, y=20,width=60,height=25)

    
    lb3=tk.Label(root,text=c,bg='#ffffff',relief=GROOVE )
    lb3.place(x=800, y=40,width=60,height=25)
    
    lb5=tk.Label(root,text=d,bg='#ffffff',relief=GROOVE)
    lb5.place(x=930, y=40,width=60,height=25)

    lb3=tk.Label(root,text=g,bg='#ffffff',relief=GROOVE )
    lb3.place(x=730, y=100,width=60,height=25)
    
    lb5=tk.Label(root,text=h,bg='#ffffff',relief=GROOVE)
    lb5.place(x=860, y=100,width=60,height=25)
    
    lb3=tk.Label(root,text=i,bg='#ffffff',relief=GROOVE )
    lb3.place(x=750, y=130,width=60,height=25)

   
    #图像显示
    #粒子群
    lb1 = tk.Label(root,image = img1)
    lb1.place(x=20, y=20, width=200,height=200)
    lb = tk.Label(root, text='粒子群参数收敛过程')
    lb.place(x=60, y=230,width=120,height=25)

    #灰度均值
    lb1 = tk.Label(root, image = img2)
    lb1.place(x=240, y=20, width=200,height=200)
    lb1 = tk.Label(root, text='灰度均值隶属函数曲线')
    lb1.place(x=280, y=230,width=120,height=25)
    #轮廓大小
    lb1 = tk.Label(root, image = img3)
    lb1.place(x=20, y=280, width=200,height=200)
    lb1 = tk.Label(root, text='轮廓大小隶属函数曲线')
    lb1.place(x=60, y=490,width=120,height=25)
 
def select2():#在函数体内进行覆盖即可实现刷新
    global img1
    img1 = ImageTk.PhotoImage(Image.open("image\\PSO\\RYD\\WQXDBD.png").resize((200,200)))
    global img4
    global img5
    global img6
    path = StringVar()
    path_ = askdirectory()
    global path1
    path.set(path_)
    path1=path_
    path1 = path1.replace("/", "\\\\")#\\表示\
    a=ryd(path1)[0]
    b=ryd(path1)[1]
    c=ryd(path1)[2]
    d=ryd(path1)[3]
    e=ryd(path1)[4]
    f=ryd(path1)[5]
    g=fx2(path1)[0]
    h=fx2(path1)[1]
    i=fx2(path1)[2]
    #显示路径
    lb = tk.Label(root,text=path1)
    lb.place(x=650, y=0, width=350,height=25)
    
    lb3=tk.Label(root,text=a,bg='#ffffff',relief=GROOVE )
    lb3.place(x=800, y=20,width=60,height=25)
    
    lb5=tk.Label(root,text=b,bg='#ffffff',relief=GROOVE)
    lb5.place(x=930, y=20,width=60,height=25)

    
    lb3=tk.Label(root,text=c,bg='#ffffff',relief=GROOVE )
    lb3.place(x=800, y=40,width=60,height=25)
    
    lb5=tk.Label(root,text=d,bg='#ffffff',relief=GROOVE)
    lb5.place(x=930, y=40,width=60,height=25)
    
    lb3=tk.Label(root,text=e,bg='#ffffff',relief=GROOVE )
    lb3.place(x=800, y=60,width=60,height=25)

    lb5=tk.Label(root,text=f,bg='#ffffff',relief=GROOVE)
    lb5.place(x=930, y=60,width=60,height=25)
    
    lb3=tk.Label(root,text=g,bg='#ffffff',relief=GROOVE )
    lb3.place(x=730, y=100,width=60,height=25)
    
    lb5=tk.Label(root,text=h,bg='#ffffff',relief=GROOVE)
    lb5.place(x=860, y=100,width=60,height=25)
    
    lb3=tk.Label(root,text=i,bg='#ffffff',relief=GROOVE )
    lb3.place(x=750, y=130,width=60,height=25)
    

    #粒子群
    lb1 = tk.Label(root,image=img1)
    lb1.place(x=20, y=20, width=200,height=200)
    lb = tk.Label(root, text='粒子群参数收敛过程')
    lb.place(x=60, y=230,width=120,height=25)

    #灰度均值
    lb1 = tk.Label(root, image = img4)
    lb1.place(x=240, y=20, width=200,height=200)
    lb1 = tk.Label(root, text='灰度均值隶属函数曲线')
    lb1.place(x=280, y=230,width=120,height=25)
    #轮廓大小
    lb1 = tk.Label(root, image = img5)
    lb1.place(x=20, y=280, width=200,height=200)
    lb1 = tk.Label(root, text='轮廓大小隶属函数曲线')
    lb1.place(x=60, y=490,width=120,height=25)
    #对比度
    lb1 = tk.Label(root, image = img6)
    lb1.place(x=240, y=280, width=200,height=200)
    lb1 = tk.Label(root, text='对比度隶属函数曲线')
    lb1.place(x=280, y=490,width=120,height=25)






#第二行
lb = tk.Label(root,text='训练数据集位置')
lb.place(x=550, y=0, width=100,height=25)

lb = tk.Label(root,text='粒子群优化计算')
lb.place(x=550, y=40,width=100,height=25 )

bt=tk.Button(root,text='填涂点',command=select1)
bt.place(x=650, y=20,width=40,height=25)
bt=tk.Button(root,text='热轧带',command=select2)
bt.place(x=650, y=60,width=40,height=25)

lb6 = tk.Label(root, text='灰度')
lb6.place(x=700, y=20,width=30,height=25)
lb7 = tk.Label(root, text='轮廓')
lb7.place(x=700, y=40,width=30,height=25)
lb7 = tk.Label(root, text='对比度')
lb7.place(x=700, y=60,width=40,height=25)
#参数表示
lb2 = tk.Label(root, text='均值')
lb2.place(x=750, y=20,width=30,height=25)
lb3=tk.Label(root,text=a,bg='#ffffff',relief=GROOVE )
lb3.place(x=800, y=20,width=60,height=25)
lb4 = tk.Label(root, text='标准差')
lb4.place(x=880, y=20,width=40,height=25)
lb5=tk.Label(root,text=b,bg='#ffffff',relief=GROOVE)
lb5.place(x=930, y=20,width=60,height=25)

lb2 = tk.Label(root, text='均值')
lb2.place(x=750, y=40,width=30,height=25)
lb3=tk.Label(root,text=c,bg='#ffffff',relief=GROOVE )
lb3.place(x=800, y=40,width=60,height=25)
lb4 = tk.Label(root, text='标准差')
lb4.place(x=880, y=40,width=40,height=25)
lb5=tk.Label(root,text=d,bg='#ffffff',relief=GROOVE)
lb5.place(x=930, y=40,width=60,height=25)

lb2 = tk.Label(root, text='均值')
lb2.place(x=750, y=60,width=30,height=25)
lb3=tk.Label(root,text=e,bg='#ffffff',relief=GROOVE )
lb3.place(x=800, y=60,width=60,height=25)
lb4 = tk.Label(root, text='标准差')
lb4.place(x=880, y=60,width=40,height=25)
lb5=tk.Label(root,text=f,bg='#ffffff',relief=GROOVE)
lb5.place(x=930, y=60,width=60,height=25)





#最大隶属
lb3 = tk.Label(root,text='隶属度计算')
lb3.place(x=550, y=110,width=90,height=25 )
lb2 = tk.Label(root, text='最大隶属度')
lb2.place(x=660, y=100,width=70,height=25)
lb3=tk.Label(root,text=g,bg='#ffffff',relief=GROOVE )
lb3.place(x=730, y=100,width=60,height=25)
lb4 = tk.Label(root, text='次大隶属度')
lb4.place(x=790, y=100,width=70,height=25)
lb5=tk.Label(root,text=h,bg='#ffffff',relief=GROOVE)
lb5.place(x=860, y=100,width=60,height=25)
lb4 = tk.Label(root, text=chr(945)+"=")
lb4.place(x=700, y=130,width=70,height=25)
lb3=tk.Label(root,text=i,bg='#ffffff',relief=GROOVE )
lb3.place(x=750, y=130,width=60,height=25)







def RCresuls1():
    M=main1(0)
    L=len(M)
    cv = Canvas(root,bg = 'white')
    cv.place(x=680, y=260,width=200,height=300)

    sc = tk.Scrollbar(cv)
    sc.pack(side=tk.RIGHT, fill=tk.Y)

    # 列表动，滚动条跟着动
    lb = tk.Listbox(cv, yscrollcommand=sc.set,justify="center")
    lb.insert("end","序号          识别结果")
    for i in range(L):
        lb.insert("end", str(i+1)+"                "+str(M[i]))
    lb.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    # 滚动条动，列表跟着动
    sc.config(command=lb.yview)

def RCresuls2():
    M=main2(0)
    L=len(M)
    cv = Canvas(root,bg = 'white')
    cv.place(x=680, y=260,width=200,height=300)

    sc = tk.Scrollbar(cv)
    sc.pack(side=tk.RIGHT, fill=tk.Y)

    # 列表动，滚动条跟着动
    lb = tk.Listbox(cv, yscrollcommand=sc.set,justify="center")
    lb.insert("end","序号          识别结果")
    for i in range(L):
        lb.insert("end", str(i+1)+"                "+str(M[i]))
    lb.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    # 滚动条动，列表跟着动
    sc.config(command=lb.yview)

def RCresuls3():
    M=main3(0)
    L=len(M)
    cv = Canvas(root,bg = 'white')
    cv.place(x=680, y=260,width=200,height=300)

    sc = tk.Scrollbar(cv)
    sc.pack(side=tk.RIGHT, fill=tk.Y)

    # 列表动，滚动条跟着动
    lb = tk.Listbox(cv, yscrollcommand=sc.set,justify="center")
    lb.insert("end","序号          识别结果")
    for i in range(L):
        lb.insert("end", str(i+1)+"                "+str(M[i]))
    lb.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    # 滚动条动，列表跟着动
    sc.config(command=lb.yview)
#第一行
btn1 = tk.Button(root,text='填涂点图像(2特征)',command=RCresuls1)
btn1.place(x=550, y=170, width=130,height=25)
btn2 = tk.Button(root,text='热轧带钢图像（2特征）',command=RCresuls2)
btn2.place(x=700, y=170, width=130,height=25)
btn3 = tk.Button(root,text='热轧带钢图像（3特征）',command=RCresuls3)
btn3.place(x=850, y=170, width=130,height=25)

#查看识别结果
lb = tk.Label(root, text='识别结果')
lb.place(x=550, y=220, width=90,height=25)




#粒子群
lb1 = tk.Label(root,bg="white")
lb1.place(x=20, y=20, width=200,height=200)
lb = tk.Label(root, text='粒子群参数收敛过程')
lb.place(x=60, y=230,width=120,height=25)

#灰度均值
lb1 = tk.Label(root, bg='white')
lb1.place(x=240, y=20, width=200,height=200)
lb1 = tk.Label(root, text='灰度均值隶属函数曲线')
lb1.place(x=280, y=230,width=120,height=25)
#轮廓大小
lb1 = tk.Label(root, bg='white')
lb1.place(x=20, y=280, width=200,height=200)
lb1 = tk.Label(root, text='轮廓大小隶属函数曲线')
lb1.place(x=60, y=490,width=120,height=25)
#对比度
lb1 = tk.Label(root, bg='white')
lb1.place(x=240, y=280, width=200,height=200)
lb1 = tk.Label(root, text='对比度隶属函数曲线')
lb1.place(x=280, y=490,width=120,height=25)



root.mainloop()




